//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "server\fn_serverExecuteDrop.sqf"
#include <tmf_constants.h>
#include <tmf_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_object","_caller","_act_id","_action","_parameters","_player","_action_id","_arguments","_item_desc","_object_array","_pickedup_item","_obj_type","_gpscoords","_marker"];
DEFAULT_PARAM(_object,TMF_EXECUTE_ACTION_OBJECT,objNull);
DEFAULT_PARAM(_caller,TMF_EXECUTE_ACTION_CALLER,objNull);
DEFAULT_PARAM(_act_id,TMF_EXECUTE_ACTION_ID,-1);
DEFAULT_PARAM(_arguments,TMF_EXECUTE_ACTION_ARGS,[]);
DEFAULT_PARAM(_action,TMF_EXECUTE_ACTION_ACTION,[]);

_action_id = 	GETVAL(_arguments,TMF_EXECUTE_ACTION_PARAM_ACTID,-1);
_object = 		GETVAL(_arguments,TMF_EXECUTE_ACTION_PARAM_TARGET,objNull);

if (!isnull _object) then {
	if (_action_id > 0) then {
		_instance_id = [_object] call FFUNC(getInstanceID);
		if (count _action  <= 0) then {
			_action = [_object,_action_id] call FFUNC(actionGet);
		};
		TRACE_1("Action",_action);
		_parameters = [_action] call FFUNC(actionGetParams);

		_item_desc = [_parameters, "ITEM_DESC", ([_object] call FFUNC(displayName)),THIS_FILE] call FFUNC(hashGet);
		_pickup_msg = [_parameters, "PICKUP_MSG", [],THIS_FILE] call FFUNC(hashGet);
		_shared_variable = [_parameters, "SHARED_VAR", "",THIS_FILE] call FFUNC(hashGet);
		_initial_status = false; //[_parameters, "SHARED_VAR_VAL", false,THIS_FILE] call FFUNC(hashGet);
		_action_title = [_parameters, "PICKUP_TITLE", "STR_TMF_PICKUP_DEFACTION",THIS_FILE] call FFUNC(hashGet);
		_pickup_code = [_parameters, "PICKUP_CODE", "",THIS_FILE] call FFUNC(hashGet);
		_shared_variable = _shared_variable call FFUNC(getStringVar);
		
		_is_picked_up = _initial_status;

		if (!isNil "_shared_variable") then {
			if (_shared_variable != "") then {
				[_instance_id,_shared_variable,_is_picked_up] spawn FFUNC(setMissionJIPVar);
				[QGVAR(all_var), [_instance_id,_shared_variable,_is_picked_up],THIS_FILE] call FFUNC(callEvent);
			};
		};
		if (typename _caller == typename objNull) then {
			_caller = name _caller;
		};
		
		_obj_var_picked = format["mission_object_pickedup_%1",_action_id];
		_obj_var = format["mission_object_pickup_player_%1",_action_id];
		OSETVARP(_object,_obj_var,nil);
		OSETVARP(_object,_obj_var_picked,_is_picked_up);
		TRACE_1("Object Dropped",ARR_3(_object,_action_id,_instance_id));
		
		_marker = OGETVAR(_object,"mission_object_pickup_marker","");
		if (IS_MARKER(_marker)) then {
			[[_marker],_instance_id] call FFUNC(marker);
			sleep 0.8234;
		};
		_marker = format ["mission_object_pickup_marker_%1",_object];
		[[_marker, getPos _object, "ICON","ColorBlue",[0.6,0.6],_item_desc,0,"mil_unknown","",0.7],_instance_id] call FFUNC(marker);
		OSETVAR(_object,"mission_object_pickup_marker",_marker);
					
		_gpscoords = [_object] call FFUNC(GPSCoords);
		_drop_msg = ["STR_TMF_DROPITEMCOORDS",_caller,_item_desc,_gpscoords];
		[QGVAR(all_message),[_drop_msg,"all",objNull,"hq"],THIS_FILE] call FFUNC(callEvent);
	};	
};

TRACE("End");
TMFPROFILERSTOP;